package com.cjzuji.rental.controller.order;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.cjzuji.rental.Bean.YoupinRequest;
import com.cjzuji.rental.dao.OrderContractDao;
import com.cjzuji.rental.dao.OrderBillDao;
import com.cjzuji.rental.dao.OrderDao;
import com.cjzuji.rental.dao.OrderUserDao;
import com.cjzuji.rental.mapper.OrderMapper;
import com.cjzuji.rental.mapper.RequestMapper;
import com.cjzuji.rental.pojo.Orders;
import com.cjzuji.rental.pojo.RequestHeard;
import com.cjzuji.rental.service.AiZuJiService;
import com.cjzuji.rental.service.YouPinService;
import com.cjzuji.rental.util.Tool;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author bag
 * @version V1.0
 * @date 2025/7/7 14:53
 * @since 1.0
 */

@RestController
@RequestMapping("/order/aizuji")
@Api(tags = "爱租机订单类")
//@Component
public class AiZuJiController {
    @Autowired
    OrderMapper orderMapper;
    @Autowired
    RequestMapper requestMapper;
    @Autowired
    AiZuJiService aiZuJiService;
    private static final Logger logger = LoggerFactory.getLogger(AiZuJiController.class);
    //http://127.0.0.1:9099/order/aizuji/getAzjInfo
    @GetMapping("/getAzjInfo")
    //获取所有数据
    //@Scheduled(fixedRate = 60 * 60 * 2000)
    @ApiOperation(value = "获取所有订单", notes = "获取所有订单")
    public List<Map<String, Object>> getAzjInfo(){
        //从数据库获取
        try {
            QueryWrapper<RequestHeard> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("id",1);
            RequestHeard requestHeard = requestMapper.selectOne(queryWrapper);
            String azjtk = requestHeard.getAzjtk();
            //System.out.println("azjtk:"+azjtk);
            List<Map<String, Object>> result = aiZuJiService.getAiZuJiList(azjtk);
            return result;
        } catch (Exception e) {
            logger.error("获取爱租机所有数据失败",e);
            return null;
        }
    }

    //获取租用中的数据
    @PutMapping("/upDateBill")
    //@Scheduled(fixedRate = 60 * 60 * 2000)
    @ApiOperation(value = "获取租用中订单", notes = "获取租用中订单")
    public List<Map<String, Object>> upDateBill(){
        //从数据库获取
        try {
            QueryWrapper<RequestHeard> queryWrapper = new QueryWrapper<>();
            RequestHeard requestHeard = requestMapper.selectOne(queryWrapper);
            String azjtk = requestHeard.getAzjtk();
            List<Map<String, Object>> result = aiZuJiService.upDateBill(azjtk);
            return result;
        } catch (Exception e) {
            logger.error("获取爱租机租用中数据失败",e);
            return null;
        }
    }

    //获取逾期订单数据
    @PutMapping("/getOverdue")
    @ApiOperation(value = "获取逾期订单", notes = "获取逾期订单")
    //@Scheduled(fixedRate = 60 * 60 * 2000)
    public List<Map<String, Object>> getOverdue(){
        try {
            QueryWrapper<RequestHeard> queryWrapper = new QueryWrapper<>();
            RequestHeard requestHeard = requestMapper.selectOne(queryWrapper);
            String azjtk = requestHeard.getAzjtk();
            List<Map<String, Object>> result = aiZuJiService.getOverdue(azjtk);
            return result;
        } catch (Exception e) {
            logger.error("获取逾期订单数据失败",e);
            return null;
        }
    }
}
